#!/usr/bin/python
import MySQLdb, sys

class Base() :
    def __init__(self):
        """
        For communication between server and database.
        """
        
        """
        self.db
        self.cur
        """
        
    def req(self, r):
        #self.cur = self.db.cursor()
        self.cur = self.db.cursor(MySQLdb.cursors.DictCursor)
        self.cur.execute(r)
        #result_set = self.cur.fetchall()
        
        """
        while (1):
            row = self.cur.fetchone()
            if row == None:
                break
            else :
                print row
            print "Number of rows returned : %d" % self.cur.rowcount
        self.cur.execute(r)
        """
        return self.cur
        #return result_set

    def connect(self):
        try:
            self.db = MySQLdb.connect("localhost", "panu", "asg09", "asg09")
            print type(self.db)
            #return self.db
        except MySQLdb.Error, e:
            print "Error : Connection to data base failed (e.args[0], e.args[1])"
            sys.exit(1)
    
    def disconnect(self):
        self.cur.close()
        self.db.close()


